package cn.oinch.bangbang.config.condition;

import cn.oinch.bangbang.config.condition.utils.PropertiesUtil;
import lombok.extern.log4j.Log4j2;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;

/**
 * 判断当前环境是不是生产环境
 *
 * @author sunHaoMing
 */
@Log4j2
public class DevCondition implements Condition {

    private static final String ENV_PROP_NAME = "env";
    private static final String DEFAULT_VALUE = "dev";

    @SuppressWarnings("NullableProblems")
    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        String value = PropertiesUtil.getProperties(ENV_PROP_NAME, DEFAULT_VALUE);
        if (value.equalsIgnoreCase(DEFAULT_VALUE)) {
            log.info("The current machine env is " + DEFAULT_VALUE + "!");
            return true;
        }
        log.info("The current machine env is " + value + "!");
        return false;
    }


}
